import { container } from './Container'

export function Inject(name: string): PropertyDecorator {
  return (target: Object, propertyKey: string | symbol) => {
    Object.defineProperty(target, propertyKey, {
      get() {
        return container.resolve(name)
      },
      set(_: Object) {
        throw new Error(`Property "${String(propertyKey)}" is injected and read-only.`)
      },
      enumerable: true,
      configurable: true
    })
  }
}